from framework.brains.exploits.browser.browser import Browser


class ExploitAPI(object):

    def __init__(self, **kwargs):

        super(ExploitAPI, self).__init__()
        self.args = kwargs
        self.exploits = list()
        self.browser = Browser()
        self.exploits.append(self.browser)

        # Loops through the available exploits
        #
        for e in self.exploits:
            if self.args is not None:
                if getattr(e, "name") == self.args["exploit"]:
                    self.run_exploit(e, self.args["name"], self.args["module"])

    @staticmethod
    def run_exploit(clz, name, module):

        """
        Runs target exploit for the selected
        platform
        """

        # Returns the list of modules
        # for the platform
        #
        wfm = clz.modules()
        if getattr(wfm, "name") == name \
                and getattr(wfm, "module") == module:
            wfm.exploit()
